﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Wormhole.Engine.Communication
{
	/// <author>Hannes Foulds</author>
	/// <date>26 September 2008</date>
	/// <summary>
	/// The base class for the dispatcher and receiver classes.
	/// </summary>
	public abstract class Listener
	{
		#region Properties

		#region Game
		private Wormhole.Engine.Game _game;
		/// <summary>
		/// The game being played.
		/// </summary>
		public Wormhole.Engine.Game Game
		{
			get
			{
				return this._game;
			}

			set
			{
				this._game = value;
				this.InitializeGameEvents();
			}
		}
		#endregion

		#region Channel
		private Wormhole.Engine.Communication.IClient _channel;
		/// <summary>
		/// The communications channel
		/// </summary>
		public Wormhole.Engine.Communication.IClient Channel
		{
			protected get
			{
				return this._channel;
			}

			set
			{
				this._channel = value;
				this.InitialzeChannelEvents();
			}

		}
		#endregion

		#endregion

		#region Constructor
		/// <summary>
		/// Initialize a new instance of the class.
		/// </summary>
		/// <param name="game">The game object.</param>
		/// <param name="channel">The communications channel</param>
		public Listener(Wormhole.Engine.Game game, Wormhole.Engine.Communication.IClient channel)
		{
			this.Game = game;
			this.Channel = channel;
		}
		#endregion

		#region Initialize Game Events
		/// <summary>
		/// Wire up the events for the game object.
		/// </summary>
		protected abstract void InitializeGameEvents();
		#endregion

		#region Initialize Channel Events
		/// <summary>
		/// Wire up the events for the communications channel.
		/// </summary>
		protected abstract void InitialzeChannelEvents();
		#endregion
	}
}
